package com.vast.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vast.entity.AnswerEntity;
import com.vast.entity.ProblemEntity;
import com.vast.service.AnswerService;
import common.utils.Result;
import common.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service("answerService")
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    MongoTemplate mongoTemplate;

    /**
     * 根据问题id查询
     * @param
     * @return
     */
    @Override
    public Result getAnswerListByProId(ProblemEntity problemEntity) {
        //构建查询条件
        Query query = new Query();
        HashMap<Object, Object> map = new HashMap<>();
        List<AnswerEntity> list = null;
        if(null != problemEntity.getProblemId() && !"".equals(problemEntity.getProblemId())){
            list = mongoTemplate.find(query.addCriteria(Criteria.where("problemId")
                    .regex(problemEntity.getProblemId())), AnswerEntity.class);
        }
        map.put("list",list);

        return new Result(StatusCode.OK,"答案问题查询成功",true,map);
    }
}
